home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Begin VB.Form frmMain
- Caption = "Demo VSFlex"
- ClientHeight = 1800
- ClientLeft = 60
- ClientTop = 345
- ClientWidth = 3135
- LinkTopic = "Form1"
- ScaleHeight = 1800
- ScaleWidth = 3135
- StartUpPosition = 3 'Windows Default
- Begin VB.CommandButton Command1
- Caption = "&Done"
- Default = -1 'True
- Height = 375
- Left = 1200
- TabIndex = 1
- Top = 1320
- Width = 855
- End
- Begin VB.Label Label1
- Caption = "Please follow along documented code and look at the immediate pane for results."
- BeginProperty Font
- Name = "Arial"
- Size = 9
- Charset = 0
- Weight = 400
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 975
- Left = 480
- TabIndex = 0
- Top = 120
- Width = 2175
- End
- Attribute VB_Name = "frmMain"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- ' Demonsration of VSFlexData object
- ' Copyright
- 1998, VocalSoft Communications
- ' All rights reserved.
- Private Sub Form_Load()
- ' Demonstrates various ways to use the VSFlexData.
- ' In order to understand how this works, step
- ' through the code line by line and read through the
- ' comments. Watch for the results in the immediate
- ' pane or the debug window.
- '=>Start here!
- VSFlexRegister "A 16-digit key"
- ' If you have aregistered version of VSFlexData, replace the
- ' string with your 16-digit key
- DemoIntrinsic
- ' Demonstrates the use of VSFlexData as
- ' intrinsic data types
- DemoMap
- ' Demonstrates the use of VSFlexData as
- ' a map
- DemoArray
- ' Demonstrates the use of VSFlexData as
- ' an array
- DemoSet
- ' Demonstrates the use of VSFlexData as
- ' an array
- DemoStack
- ' Demonstrates the use of VSFlexData as
- ' a stack
- DemoQueue
- ' Demonstrates the use of VSFlexData as
- ' a queue
- DemoFile
- ' Demonstrates the use of VSFexData as a self-
- ' contained object smart enough to know how to
- ' write itself to a file and read itself back
- ' from a file
- DemoMethods
- ' Demonstrates various utility methods of the
- ' onject
- End Sub
- Private Sub DemoIntrinsic()
- ' Demonstrates the use of object as any of the
- ' intrinsic data types
- Dim x As VSFlexData
- Set x = New VSFlexData
- Debug.Print "Demo of intrinsic data types"
- Debug.Print "============================"
- x = 5
- Debug.Print x
- ' As an integer
- x = "My name is John Doe"
- Debug.Print x
- ' As a string
- x = 5.12314 + 1
- Debug.Print x
- ' As a floating point
- ' Can be used as any of the VB Intrinsic data types
- Debug.Print
- End Sub
- Private Sub DemoMap()
- ' Demonstrates the use of object as a map
- ' A map is like a VB collection, but greatly
- ' enhanced
- Dim x As VSFlexData
- Dim k As VSFlexData
- Set x = New VSFlexData
- Debug.Print "Demo of Maps"
- Debug.Print "============"
- With x
- .SetMap
- !MinWidth = 10
- !MaxWidth = 7500
- ' Notice that you just start using the map.
- ' Unlike a collection, when using a map you don't
- ' have to worry about adding items, duplicate keys, etc.
- ' Once you have set the object as a map, just
- ' keep adding items to it with the slot operator (!).
-
- Set !Form = Me
- !Form.Caption = "VSFlexData Demo"
- ' Also notice that you can set a member of a map to
- ' an object. In this instance this object is a form.
- ' To build more complicated data structures, you could use
- ' maps of maps, maps of arrays, arrays of maps --
- ' the possibilities are limitless.
-
- Debug.Print !MinWidth
- Debug.Print !MaxWidth
- Debug.Print !Form.Name
- Debug.Print
- ' This is how you access map members
-
- Debug.Print .DebugPrint
- ' This is another way you could take a
- ' quick look at the data in your object
-
- Set k = .GetKeys
- Debug.Print k(1) & " = " & x(k(1))
- Debug.Print k(2) & " = " & x(k(2))
- Debug.Print k(3) & " = " & x(k(3)).Name
- ' Notice how you can get the keys of a map. You can't
- ' do this with a VB collection.
-
- If .Exists("MinWidth") Then
- !MinWidth = 0
- Debug.Print "Now MinWidth = " & !MinWidth
- End If
- ' You could use the Exists method to find out
- ' if a certain key exists in the map
- End With
- Debug.Print
- End Sub
- Private Sub DemoArray()
- ' Demonstrates the use of object as an array
- Dim x As VSFlexData
- Dim k As VSFlexData
- Set x = New VSFlexData
- Set k = New VSFlexData
- x.Tag = "x"
- k.Tag = "k"
- Debug.Print "Demo of arrays"
- Debug.Print "=============="
- With x
- .SetArray
- x(1) = "This"
- x(2) = "is"
- x(3) = "a"
- x(4) = "test."
- Debug.Print x.DebugPrint
- ' This is a dynamic array. Notice that you don't have to
- ' specify the number of elements, and you certainly
- ' don't have to ReDim the array -- just keep adding elements!
-
- .SetArray 3
- x(1) = "This"
- x(2) = "is"
- x(3) = "a"
- ' This is a fixed array. Since you specified the
- ' number of elements in the SetArray method,
- ' the following line if uncommented would
- ' cause a runtime error:
- ' x(4) = "test."
-
- k.SetArray 5
- Set x(1) = k
-
- x(1)(1) = "This"
- x(1)(2) = "is"
- x(1)(3) = "another"
- x(1)(4) = "test."
- Debug.Print x.DebugPrint
- ' This is how you could use a multidimensional array.
- ' This particular array is a 2-dimensional array, but
- ' there is no reason why you can't use more than 2 dimensions.
-
- k.AddLast "Wow! that's cool."
- ' Another way to add an element to an array
- Debug.Print x.DebugPrint
- End With
- Debug.Print
- End Sub
- Private Sub DemoFile()
- ' Demonstrates the use of object as a
- ' self-contained data structure smart enough
- ' to save itself to a file and read itself
- ' from a file
- Dim str As String
- Dim x As VSFlexData: Set x = New VSFlexData
- Dim k As VSFlexData: Set k = New VSFlexData
- x.SetSet 5, 4, 3, 2, 1
- ' Initialize x as a set of (5,4,3,2,1)
- x.Export App.Path & "\" & "Test.VSF"
- ' Export x to a file
- k.Import App.Path & "\" & "Test.VSF"
- ' Import k from the file
- Debug.Print x.DebugPrint
- Debug.Print
- ' See what's in x
- Debug.Print k.DebugPrint
- Debug.Print
- ' See what's in k
- End Sub
- Private Sub DemoSet()
- ' Demonstrates the use of object as a set
- Dim x As VSFlexData
- Set x = New VSFlexData
- Debug.Print "Demo of set"
- Debug.Print "==========="
- ' A set can be used to define a constant set of values
- ' Once defined, niether more members can be added nor
- ' the existing members can be changed
- x.SetSet 100, 200, "This is a strng", 244.5
- ' Create a set
- Debug.Print x.DebugPrint
- ' Print the values
- Debug.Print x.Find(200)
- ' You can get the index of a value
- Debug.Print x.Exists(100)
- ' You can determne whether a value exists
- Debug.Print
- End Sub
- Private Sub DemoStack()
- ' Demonstrates the use of object as a stack
- Dim x As VSFlexData
- Set x = New VSFlexData
- Debug.Print "Demo of stack"
- Debug.Print "============="
- ' A stack can be used to to implement the LIFO
- ' or Last-In-First-Out data structure.
- ' You can only PUSH elements on a stack
- ' and POP them out
- x.SetStack
- ' Create a stack
- x.Push 100
- ' Push an integer to the stack
- x.Push 200.25
- ' Push a real to the stack
- x.Push "This is a stack"
- ' Push a string to the stack
- x.Push Me
- ' Push an object to the stack
- Debug.Print x.Find(200)
- ' Find 200 on the stack
- Debug.Print x.Exists(200.25)
- ' Does 200.25 exist on the stack?
- Debug.Print x.Pop.Name
- Debug.Print x.Pop
- Debug.Print x.Pop
- Debug.Print x.Pop
- ' Pop values from stack
- Debug.Print
- End Sub
- Private Sub DemoQueue()
- ' Demonstrates the use of object as a stack
- Dim x As VSFlexData
- Set x = New VSFlexData
- Debug.Print "Demo of Queue"
- Debug.Print "============="
- ' A queue can be used to to implement the FIFO
- ' or Frst-In-First-Out data structure.
- ' You can only PUSH elements on a queue
- ' and POP them out
- x.SetQueue
- ' Create a stack
- x.Push 100
- ' Push an integer to the stack
- x.Push 200.25
- ' Push a real to the stack
- x.Push "This is a queue"
- ' Push a string to the stack
- x.Push Me
- ' Push an object to the stack
- Debug.Print x.Find(200)
- ' You can get the index of a value
- Debug.Print x.Exists(200.25)
- ' You can determne whether a value exists
- Debug.Print x.Pop
- Debug.Print x.Pop
- Debug.Print x.Pop
- Debug.Print x.Pop.Name
- ' Print the values
- Debug.Print
- End Sub
- Private Sub DemoMethods()
- ' Demonstrates various methods of the VSFlexData object
- Dim vsMap As VSFlexData: Set vsMap = New VSFlexData
- Dim vsMap2 As VSFlexData: Set vsMap2 = New VSFlexData
- Dim vsArray As VSFlexData: Set vsArray = New VSFlexData
- Dim vsArray2 As VSFlexData: Set vsArray2 = New VSFlexData
- Debug.Print "Demo various methods"
- Debug.Print "===================="
- vsMap.SetMap
- vsArray.SetArray
- ' Set one of the variables as a map
- ' and the other one as an array
- With vsMap
- !Name = "John Doe"
- !Phone = 5551212
- End With
- ' Put some initial data in the map
- vsArray(1) = "Mr."
- vsArray(2) = "Mrs."
- vsArray(3) = "Miss"
- ' Put some initial data in the array
- Debug.Print vsMap.IsNumeric("Phone")
- Debug.Print vsMap.IsInteger("Phone")
- Debug.Print vsMap.IsLong("Phone")
- Debug.Print vsMap.IsString("Name")
- Debug.Print vsArray.IsString(2)
- Debug.Print vsArray.IsObject(1)
- ' Notice how you can find out the type of
- ' each member element
- Debug.Print
- Debug.Print vsArray.Find("Mrs.")
- Debug.Print vsMap.Find("Phone")
- Debug.Print vsMap(vsMap.Find("Phone"))
- ' The Find method finds returns the position of a
- ' given element in the array. In case of a map, it
- ' returns the position of the slot or key name.
- Debug.Print
- Debug.Print vsArray.Exists("Miss")
- Debug.Print vsMap.Exists("Phone")
- Debug.Print vsMap.Exists("Mr.")
- ' Notice how you can find out if a given element exists
- ' in an array or a given key exists in a map.
- Debug.Print
- vsArray.AddFirst "Sir"
- vsArray.AddLast "Madam"
- Debug.Print vsArray(1)
- Debug.Print vsArray(vsArray.Length)
- ' You can also add elements in the first
- ' or the last position
- Debug.Print
- vsMap2.Become vsMap
- vsMap!Phone = 911
- vsMap!Name = "Emergency"
- Debug.Print vsMap2!Phone
- Debug.Print vsMap2!Name
- ' Become is one method that you could use
- ' to copy an existing VSFlexData object to another.
- ' Notice that after we copied vsMap to vsMap2,
- ' we changed vsMap -- but this did not effect vsMap.
- ' VB Collections lack this functionality
- Debug.Print
- Set vsArray2 = vsArray.Clone
- Debug.Print vsArray2.DebugPrint
- ' Clone performs the same operation as Become
- ' GetObjectString returns a string for the data
- ' of that object
- Debug.Print
- End Sub
- Private Sub Command1_Click()
- Unload Me
- End Sub
-